{% extends 'layout/basic.html' %}
{% load static %}
{% block title %}用户登录{% endblock %}
{% block css %}
    <link rel="stylesheet" href="{% static 'css/account.css' %}">
{% endblock %}

{% block content %}
    <div class="account">
       <div class="title">用户登录</div>
        <form method="post">
        {% csrf_token %}
          {% for filed in form %}
              <div class="form-group">
              {% if filed.name == 'code' %}
              <label for="{{ field.id_for_label }}">{{ filed.label }}</label>
                  <div class="clearfix">
                      <div class="col-md-6" style="padding-left: 0">{{ filed }}<span class="err_msg">{{ filed.errors.0 }}</span></div>
                      <div class="col-md-6"><img src="{% url 'image_code' %}" alt="验证码" id="imageCode" title="点击更换图片"></div>
                  </div>
              {% else %}
                  <label for="{{ field.id_for_label }}">{{ filed.label }}</label>
                    {{ filed }}
                    <span class="err_msg">{{ filed.errors.0 }}</span>
              {% endif %}
              </div>
          {% endfor %}
        <div style="float: right">
            <a href="{% url 'login_sms' %}">短信验证码登录？</a>
        </div>
          <input type="submit" class="btn btn-primary" value="登录">
        </form>
    </div>

{% endblock %}

{% block js %}
    <script>
        $(function () {
            $('#imageCode').click(function () {
                var oldSrc=$(this).attr('src')
                $(this).attr('src',oldSrc+'?')//更换访问地址，重新请求图片
            })
        })
    </script>
{% endblock %}